using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.obj
{
[System.Serializable]
public  class CharacterController : Singleton
 {

    public float slopeLimit ;
     public float stepOffset ;
     public float skinWidth ;
     public float minMoveDistance ;
     public cfg.map.Vector3 center  = new cfg.map.Vector3();
     public float radius ;
     public float height ;
     


    public const int TYPE_ID = 34147196;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(9);
        os.WriteSize(Tag.BOOL | (1 << Tag.TAG_SHIFT));  os.WriteBool(enable);  
         os.WriteSize(Tag.INT | (2 << Tag.TAG_SHIFT));  os.WriteInt(cfgId);  
         os.WriteSize(Tag.FLOAT | (9 << Tag.TAG_SHIFT));  os.WriteFloat(slopeLimit);  
         os.WriteSize(Tag.FLOAT | (3 << Tag.TAG_SHIFT));  os.WriteFloat(stepOffset);  
         os.WriteSize(Tag.FLOAT | (4 << Tag.TAG_SHIFT));  os.WriteFloat(skinWidth);  
         os.WriteSize(Tag.FLOAT | (5 << Tag.TAG_SHIFT));  os.WriteFloat(minMoveDistance);  
         os.WriteSize(Tag.BEAN | (6 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_map_Vector3(center,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.FLOAT | (7 << Tag.TAG_SHIFT));  os.WriteFloat(radius);  
         os.WriteSize(Tag.FLOAT | (8 << Tag.TAG_SHIFT));  os.WriteFloat(height);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.BOOL | (1 << Tag.TAG_SHIFT)):   enable = os.ReadBool(); break;  
             case (Tag.INT | (2 << Tag.TAG_SHIFT)):   cfgId = os.ReadInt(); break;  
             case (Tag.FLOAT | (9 << Tag.TAG_SHIFT)):   slopeLimit = os.ReadFloat(); break;  
             case (Tag.FLOAT | (3 << Tag.TAG_SHIFT)):   stepOffset = os.ReadFloat(); break;  
             case (Tag.FLOAT | (4 << Tag.TAG_SHIFT)):   skinWidth = os.ReadFloat(); break;  
             case (Tag.FLOAT | (5 << Tag.TAG_SHIFT)):   minMoveDistance = os.ReadFloat(); break;  
             case (Tag.BEAN | (6 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); center = cfg.Extensions.unmarshal_compatible_cfg_map_Vector3(os); os = _oldOs; break; }   
             case (Tag.FLOAT | (7 << Tag.TAG_SHIFT)):   radius = os.ReadFloat(); break;  
             case (Tag.FLOAT | (8 << Tag.TAG_SHIFT)):   height = os.ReadFloat(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "CharacterController");
        ele.WriteStartElement("enable"); ele.WriteAttributeString("id", "1"); ele.WriteBool(enable); ele.WriteEndElement();
         ele.WriteStartElement("cfgId"); ele.WriteAttributeString("id", "2"); ele.WriteInt(cfgId); ele.WriteEndElement();
         ele.WriteStartElement("slopeLimit"); ele.WriteAttributeString("id", "9"); ele.WriteFloat(slopeLimit); ele.WriteEndElement();
         ele.WriteStartElement("stepOffset"); ele.WriteAttributeString("id", "3"); ele.WriteFloat(stepOffset); ele.WriteEndElement();
         ele.WriteStartElement("skinWidth"); ele.WriteAttributeString("id", "4"); ele.WriteFloat(skinWidth); ele.WriteEndElement();
         ele.WriteStartElement("minMoveDistance"); ele.WriteAttributeString("id", "5"); ele.WriteFloat(minMoveDistance); ele.WriteEndElement();
         ele.WriteStartElement("center"); ele.WriteAttributeString("id", "6"); cfg.Extensions.xml_marshal_cfg_map_Vector3(center,ele); ele.WriteEndElement();
         ele.WriteStartElement("radius"); ele.WriteAttributeString("id", "7"); ele.WriteFloat(radius); ele.WriteEndElement();
         ele.WriteStartElement("height"); ele.WriteAttributeString("id", "8"); ele.WriteFloat(height); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  enable = ele.ReadBool(); break; 
                 case 2:  cfgId = ele.ReadInt(); break; 
                 case 9:  slopeLimit = ele.ReadFloat(); break; 
                 case 3:  stepOffset = ele.ReadFloat(); break; 
                 case 4:  skinWidth = ele.ReadFloat(); break; 
                 case 5:  minMoveDistance = ele.ReadFloat(); break; 
                 case 6:  center = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case 7:  radius = ele.ReadFloat(); break; 
                 case 8:  height = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "enable":  enable = ele.ReadBool(); break; 
                 case "cfg_id":  cfgId = ele.ReadInt(); break; 
                 case "slope_limit":  slopeLimit = ele.ReadFloat(); break; 
                 case "step_offset":  stepOffset = ele.ReadFloat(); break; 
                 case "skin_width":  skinWidth = ele.ReadFloat(); break; 
                 case "min_move_distance":  minMoveDistance = ele.ReadFloat(); break; 
                 case "center":  center = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case "radius":  radius = ele.ReadFloat(); break; 
                 case "height":  height = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
